﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Collections.Generic;

namespace GoShopping.Web.ProductManager
{
    public partial class DeletedProduct : System.Web.UI.Page
    {
        BLL.ProductBean pb = new GoShopping.BLL.ProductBean();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SetControlCommon.GetDDLType(ddlType);
                GetGVData(null);
            }
            
        }

        private void GetGVData(string filterString)
        {
            if (string.IsNullOrEmpty(filterString) || filterString == "-1")
            {
                //IList<Model.Product> listPrdt = pb.GetAllProduct();
                IList<Model.Product> listPrdt = pb.GetProductList(" AND IsShowOnSale='false'");
                extGVDeletedPrdt.DataSource = listPrdt;
                extGVDeletedPrdt.DataBind();
            }
            else
            {
                IList<Model.Product> listPrdt = pb.GetProductList(" AND IsShowOnSale='false' AND ProductTypeID=" + filterString);
                extGVDeletedPrdt.DataSource = listPrdt;
                extGVDeletedPrdt.DataBind();
            }
        }

        protected void btnRestore_Click(object sender, EventArgs e)
        {
            // 使用ArrayList记录选择的项
            ArrayList selList = new ArrayList();
            int i = 0;
            // 遍历数据集
            foreach (GridViewRow row in this.extGVDeletedPrdt.Rows)
            {
                // 获取行首的CheckBox，判断是否为Checked
                CheckBox cb = (CheckBox)row.FindControl("cbSingle");
                if (cb.Checked == false)
                {
                    continue;
                }
                //// 若为Checked,将信息添加到ArrayList
                selList.Add(((Label)row.FindControl("lblID")).Text);
                i++;
            }
            // 若遍历完成后ArrayList为空，则表示未选中任何项，页面提示
            if (selList.Count == 0)
            {
                return;
            }
            // 调用逻辑方法，执行删除操作
            BLL.ProductBean dbb = new GoShopping.BLL.ProductBean();
            for (int j = 0; j < selList.Count; j++)
            {
                pb.UpdateProductShowOnSale(Convert.ToInt16(selList[j]), true);
            }
            // 重新绑定
            GetGVData(ddlType.SelectedValue);
        }

        protected void cbAll_CheckedChanged(object sender, EventArgs e)
        {
            // 遍历数据集的所有数据项
            foreach (GridViewRow row in this.extGVDeletedPrdt.Rows)
            {
                // 取得数据项行首的CheckBox，使其Checked属性与表头的CheckBox同步
                CheckBox subCB = (CheckBox)row.FindControl("cbSingle");
                subCB.Checked = ((CheckBox)sender).Checked;
            }
        }

        protected void ddlType_SelectedIndexChanged(object sender, EventArgs e)
        {
            GetGVData(ddlType.SelectedValue);
        }

        public string GetPrdtTypeName(object obj)
        {
            BLL.ProductTypeBean ptb = new GoShopping.BLL.ProductTypeBean();
            return ptb.GetProductType(Convert.ToInt32(obj)).TypeName;
        }

        public string GetSupplierName(object obj)
        {
            BLL.ProductSuplyBean psb = new GoShopping.BLL.ProductSuplyBean();
            return psb.GetProductSuply(Convert.ToInt32(obj)).Name;
        }

        public string GetIsOnSale(object obj)
        {
            if (Convert.ToBoolean(obj))
            {
                return "是";
            }
            else
            {
                return "否";
            }
        }

        //protected void btnDel_Click(object sender, EventArgs e)
        //{
        //    // 使用ArrayList记录选择的项
        //    ArrayList selList = new ArrayList();
        //    int i = 0;
        //    // 遍历数据集
        //    foreach (GridViewRow row in this.extGVDeletedPrdt.Rows)
        //    {
        //        // 获取行首的CheckBox，判断是否为Checked
        //        CheckBox cb = (CheckBox)row.FindControl("cbSingle");
        //        if (cb.Checked == false)
        //        {
        //            continue;
        //        }
        //        //// 若为Checked,将信息添加到ArrayList
        //        selList.Add(((Label)row.FindControl("lblID")).Text);
        //        i++;
        //    }
        //    // 若遍历完成后ArrayList为空，则表示未选中任何项，页面提示
        //    if (selList.Count == 0)
        //    {
        //        return;
        //    }
        //    // 调用逻辑方法，执行删除操作
        //    BLL.ProductBean dbb = new GoShopping.BLL.ProductBean();
        //    for (int j = 0; j < selList.Count; j++)
        //    {
        //        pb.UpdateProductShowOnSale(Convert.ToInt16(selList[j]), true);
        //    }
        //    // 重新绑定
        //    GetGVData(null);
        //}
    }
}
